<script type="text/javascript">

function selectAll(field)
{
	if (document.myForm.selector.checked == true) {
	for (i = 0; i < field.length; i++) {
			field[i].checked = true
		}
	}
	else {
		for (i = 0; i < field.length; i++) {
			field[i].checked = false
		}
	}	
}

</script>
<?php
include_once 'admin-functions.php';
if ((isset($_SESSION['logged_in'])) && ($_SESSION['account_rank']<2)) {} else {header('Location: page.php');exit;}

/* Listing*/
if (isset($_GET['edit']) == 0 && isset($_GET['delete']) == 0 && isset($_GET['view']) == 0 && isset($_POST['id']) == 0)  {
	echo '<form name="myForm" action="page.php" method="GET">
	<input type="hidden" name="p" value="manage" />
	<input type="hidden" name="delete" value="yes" />
	<table>' . "\n";
	list_posts($blog_db);
	echo "\n" . '</table>
	<input style="width:1em;" value="20" name="selector" onclick="selectAll(document.myForm.boxes)" type="checkbox" />
	<input style="width:4em;" type="submit" value="Delete" /></form>';
}

/* Preview */
if (isset($_GET['view']) && isset($_SESSION['logged_in'])) {

	echo '<form action="page.php" method="GET">
		<input type="hidden" name="p" value="manage" />
		<div><a href="page.php?p=drafts">Back</a> | 
		<input type="hidden" name="edit" value="';
	echo $_GET['view'];
	echo '" /><input type="submit" value="Edit" /></form>';	
	echo preview($_GET['view'], $blog_db);


}

/* Edit */
if (isset($_POST['id']) && isset($_SESSION['logged_in'])) {


}

/* Delete */
if (isset($_GET['delete']) && $_SESSION['account_rank']<1 && isset($_SESSION['logged_in'])) {
	foreach($_GET as $key => $value) {
		if ($value=="on") {
			echo delete_post($key, $blog_db);
		}
	}
}

/* BEGIN THE EDIT PAGE */
if (isset($_GET['edit']) && isset($_SESSION['logged_in'])) {

}


/* Error */
if (isset($_GET['delete']) && $_SESSION['account_rank']>=3) { echo "<p><strong>Oops!</strong> Make sure you have permission to delete entries!</p>";}
if (isset($_GET['edit']) && $_SESSION['account_rank']>=3) { echo "<p><strong>Oops!</strong> Make sure you have permission to edit entries!</p>";}



?>